<!doctype html>
<title>Source phase imports</title>

<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script type=module>
setup({ single_test: true });

import source exportedNamesSource from "./resources/exported-names.wasm";

assert_true(exportedNamesSource instanceof WebAssembly.Module);
const AbstractModuleSource = Object.getPrototypeOf(WebAssembly.Module);
assert_equals(AbstractModuleSource.name, "AbstractModuleSource");
assert_true(exportedNamesSource instanceof AbstractModuleSource);

assert_array_equals(WebAssembly.Module.exports(exportedNamesSource).map(({ name }) => name).sort(),
                    ["func", "glob", "mem", "tab"]);

const wasmImportFromWasmSource = await import.source("./resources/wasm-import-from-wasm.wasm");

assert_true(wasmImportFromWasmSource instanceof WebAssembly.Module);

let logged = false;
const instance = await WebAssembly.instantiate(wasmImportFromWasmSource, {
  "./wasm-export-to-wasm.wasm": {
    log () {
      logged = true;
    }
  }
});
instance.exports.logExec();
assert_true(logged);

done();
</script>
